popupw={
	  popupInit:function(objWrapId,objClass,popupId,popupPos,popupPosNum,eventType){ 
	   var objWrap=document.getElementById(objWrapId);
	   if(!objWrap) return;
	   var popup=document.getElementById(popupId);
	   if(!popup) return;
	   var objs=objWrap.getElementsByTagName("*");
	   var eType=eventType || "onclick";
	   for(var i=0;i<objs.length;i++){
		   if(objs[i].className.indexOf(objClass)<0) continue;
		   if(objs[i].tagName=="A"){
				objs[i].setAttribute("href","javascript:;");
		   }
		   objs[i][eType]=function(){
			   popupw.closeP();
			   popupw.returnSrc(objWrap);
			   popupw.openP(this,popup,popupPos,popupPosNum);
		   }
		   if(eType=="onmouseover"){
				objs[i]["onmouseout"]=popupw.closeP;  
		   }
	   }
	   var popupAs=popup.getElementsByTagName("*");
	   for(var j=0;j<popupAs.length;j++){
		  if(popupAs[j].className.indexOf("close")<0) continue;
		  if(popupAs[j].tagName=="A"){
				popupAs[j].setAttribute("href","javascript:;");
		   }
		  popupAs[j].onclick=function(){
			  popupw.closeP(); 
		  } 
	   }
	},
	openP:function(obj,popup,popupPos,popupPosNum,url){
		//AJAX设置popup内容
		if(url){
			new Ajax.Request(url,
	  		{
			    method:'post',
			    parameters: {r: Math.random()},//加个随机数，防止页面不刷新
			    onSuccess: function(transport){			      
			      	var response = transport.responseText || "no response text";
			      	popup.innerHTML = response;	    
			    },
			    onFailure: function(){ alert('失败，请稍后再试...') }
			  });
		}
		popup.style.display="block";
		var pos=size=[];
		pos=popupw.getPos(obj);
		size=[obj.offsetWidth,obj.offsetHeight];
		var popupWidth=popup.offsetWidth;
		var x=y=0;
		var ppn=popupPosNum?popupPosNum:0;
		if(popupPos=="left"){
			x=pos[0]-popupPosNum;
		}
		if(popupPos=="right"){
			x=pos[0]+size[0]-popupWidth+popupPosNum;
		}
		if(popupPos=="middle"){
			x=pos[0]+size[0]/2-popupWidth/2;
		}
		x=x<0?0:x;
		y=pos[1]+size[1];
		popup.style.left=x+"px";
		popup.style.top=y+"px";
	},
	getPos:function(elem){
		var posX=posY=0;
		while(elem !=null){
			posX+=elem.offsetLeft;
			posY+=elem.offsetTop;
			elem=elem.offsetParent;
		}
		return [posX,posY];
	},
	closeP:function(){
		var divs=document.getElementsByTagName("div");
		for(var i=0;i<divs.length;i++){
			if(divs[i].className.indexOf("popup")<0) continue;	
			divs[i].style.display="none";
		}	
	},
	returnSrc:function(imgWrap){
		var imgs=imgWrap.getElementsByTagName("img");
		for(var i=0;i<imgs.length;i++){
			if(imgs[i].className !="popupReply") continue;
			if(imgs[i].src.indexOf("pages/images/minus.gif")>=0) ;
			else
				imgs[i].src="../pages/images/minus.gif"; //2010。12。23更改图片地址 shm
		}
	}
}





